package top.tangyh.lamp.care.mapper;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import top.tangyh.basic.base.mapper.SuperMapper;
import top.tangyh.basic.utils.DateUtils;
import top.tangyh.lamp.care.entity.BCarePgRecord;
import org.springframework.stereotype.Repository;
import top.tangyh.lamp.common.utils.PDateUtils;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * <p>
 * Mapper 接口
 * 护理入科评估表
 * </p>
 *
 * @author zqb
 * @date 2024-07-26 10:31:53
 * @create [2024-07-26 10:31:53] [zqb] [代码生成器生成]
 */
@Repository
public interface BCarePgRecordMapper extends SuperMapper<BCarePgRecord> {


    default boolean checkPgByPfTime(String patientIdent, LocalDateTime pfTime, String pfr){
        Date start = PDateUtils.stringToDate(DateUtils.format(new Date(PDateUtils.getTimestampOfDateTime(pfTime)),PDateUtils.DATE_TIME_MINUTE_PATTERN)+":00",PDateUtils.DATE_TIME_PATTERN);
        Date end = PDateUtils.stringToDate(DateUtils.format(new Date(PDateUtils.getTimestampOfDateTime(pfTime)),PDateUtils.DATE_TIME_MINUTE_PATTERN)+":59",PDateUtils.DATE_TIME_PATTERN);
        LambdaQueryWrapper<BCarePgRecord> queryWrapper = new LambdaQueryWrapper<>();
        Set<Integer> set = new HashSet<>();
        set.add(1);
        set.add(2);
        queryWrapper.eq(BCarePgRecord::getPatientIdent,patientIdent)
                .in(BCarePgRecord::getType, set)
                .eq(BCarePgRecord::getPfr,pfr)
                .ge(BCarePgRecord::getPfTime,start)
                .le(BCarePgRecord::getPfTime,end);
        List<BCarePgRecord> olds = selectList(queryWrapper);
        if(CollectionUtil.isNotEmpty(olds)){
            return true;
        }
        else{
            return false;
        }
    }
}


